<template>
  <div class="child">
    vue3+ts+element-plus+axios+pinia
  </div>


  <el-button @click="login">模拟登录</el-button>
</template>

<script setup lang="ts">
import { reactive } from "vue";
import { loginApi } from "../api/modules";
import { ElMessage } from "element-plus";
// import { userStore } from "@/stores/allStores";
import { useUserStore } from "@/stores/modules/user";
const userStore = useUserStore();
const loginMesg = reactive({
  username: "sq",
  password: "123456",
  encrypttype: 0,
});
const login = async () => {
  try {
    const res = await loginApi(loginMesg);
    // 能运行这里说明请求成功
    ElMessage.success("登录成功");
    userStore.setToken(res.data.token);
    userStore.setUserInfo(res.data);
  } catch (error) {
    console.log("error", error);
  }
};
</script>
<style scoped>
.child {
  .p {
    color: red;
  }
}

.icon {
  width: 100px;
  height: 100px;
  color: red;
  margin-top: 5px;
}
</style>
